package com.lefeng.cockpit.datax.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lefeng.cockpit.common.bean.po.job.JobLogPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.Map;

/**
 * job log
 *
 * @author weifw
 */
@Mapper
public interface JobLogMapper extends BaseMapper<JobLogPO> {

    @Select(
            "<script>" +
                    "SELECT " +
                    "   COUNT(handle_code) triggerDayCount, " +
                    "   COALESCE(SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end),0) as triggerDayCountRunning, " +
                    "   COALESCE(SUM(CASE WHEN handle_code = 200 then 1 else 0 end),0) as triggerDayCountSuc " +
                    "FROM dc_datax_job_log " +
                    "WHERE trigger_time BETWEEN #{from} and #{to}" +
                    "</script>")
    Map<String, Object> findLogReport(@Param("from") Date from, @Param("to") Date to);

}
